<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/gray/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/icon.css"/>
    <link rel="stylesheet" type="text/css" href="/js/easyui/themes/color.css"/>
    <script type="text/javascript" src="/js/easyui/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/acyFramework/easyui_validate_ext.js"></script>
    <script type="text/javascript" src="/js/acyFramework/aqucy.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/icon.css"/>
    <style type="text/css">
        .tdRightPadding {
            padding-right: 20px;
            width: 170px;
            text-align: left;
        }

    </style>
    <script type="text/javascript">
        $.parser.auto = false;
        var del, subDel;
        var init = true;
        var pop;
        function showCombboxData(itemId, code) {
            var data = $("#" + itemId).combobox("getData");
            if (data == null || data == "") {
                $("#" + itemId).combobox("reload", "/getDict?code=" + code);
            }
        }
        $.parser.onComplete = function (context) {
            $("#Loading").css("display", "none");
        };
        $(document).ready(function () {
            /////////////////////////字典匹配////////////////////////////////////////////////////
            function createDataGrid() {
                var initUrl = '/project/shangPin?op=view';
                initUrl = encodeURI(initUrl);
                $('#dg').datagrid(
                        {

                            url: initUrl,
                            idField: 'id',
                            title: '学生作业',
                            fit: true,
                            fitColumns: true,
                            pageSize: 10,
                            pagination: true,
                            singleSelect: false,
                            selectOnCheck: true,
                            sortName: 'id',
                            pageList: [10, 30, 50, 100, 300, 500, 800, 1000],
                            sortOrder: 'desc',
                            ctrlSelect: true,
                            rownumbers: true,
                            showFooter: true,
                            frozenColumns: [[]],
                            columns: [
                                [

                                    {
                                        field: 'id',
                                        title: '主键',
                                        hidden: false,
                                        checkbox: true,
                                        sortable: true,
                                        width: 120
                                    },
                                    {
                                        field: 'name',
                                        title: '商品名称',
                                        sortable: true,
                                        width: 120
                                    },
                                    {
                                        field: 'pingPai',
                                        title: '品牌',
                                        sortable: true,
                                        width: 120
                                    },
                                    {
                                        field: 'jiaGe',
                                        title: '价格',
                                        sortable: true,
                                        width: 120
                                    },
                                    {
                                        field: 'opt', title: '操作', width: 200, formatter: function (value, rec, index) {
                                        if (!rec.id) {
                                            return '';
                                        }
                                        var href = "<a href='javascript:' title='删除' onclick='del(" + rec.id + ")'><img src='/icons/delete.png'/></a>";
                                        return href;
                                    }
                                    }
                                ]
                            ],
                            onLoadSuccess: function (data) {
                                $("#dg").datagrid("clearSelections");
                            },
                            onClickRow: function (rowIndex, rowData) {
                                rowid = rowData.id;
                                gridname = 'dg';
                            },
                            onDblClickRow: function (index, row) {
                                view();
                            }
                        });
            }
            createDataGrid();
            //提示信息
            function showMsg(msg) {
                $.messager.show({
                    title: '提示',
                    msg: msg,
                    showType: 'show'
                });
            }

            function getDataGridSelectedRow() {
                var row = $('#dg').datagrid('getSelected');
                return row;
            }

            //获取表格选中行的指定列(单选)
            function getDataGridSelectedData(field) {
                var row = $('#dg').datagrid('getSelected');
                if (row != null) {
                    value = row[field];
                } else {
                    value = '';
                }
                return value;
            }

            //获取表格选中行的指定列(多选)
            function getDataGridSelectedDatas(field) {
                var ids = '';
                var rows = $('#dg').datagrid('getSelections');
                for (var i = 0; i < rows.length; i++) {
                    ids += rows[i][field];
                    ids += ',';
                }
                ids = ids.substring(0, ids.length - 1);
                return ids;
            }

            function action(fm, op) {
                $.messager.progress({
                    title: '请稍后',
                    msg: '操作进行中...'
                });
                fm.form('submit', {
                    url: "/project/shangPin",
                    onSubmit: function () {
                        var isValid = $(this).form('validate');
                        if (!isValid) {
                            $.messager.progress('close');	// hide progress bar while the form is invalid
                        }
                        return isValid;	// return false will stop the form submission
                    },
                    success: function (e) {
                        var json = $.parseJSON(e);
                        if (json.errcode != 0) {
                            $.messager.alert("错误", json.errmsg, "error");
                        } else {
                            showMsg("操作成功");
                            if (op == "add") {
                                $('#addDialog').dialog('close');
                            } else if (op == "edit") {
                                $('#editDialog').dialog('close')
                            }
                            refresh();
                        }
                        $.messager.progress('close');	// hide progress bar while submit successfully
                    }
                });
            }

            //添加
            function add() {
                $('#addForm').form('reset');
                $('#addDialog').dialog('open').dialog('setTitle', '添加');
            }

            $("#add").click(function () {
                add();
            });
            //编辑
            function edit() {
                var row = getDataGridSelectedRow();
                if (!row || row == undefined || row == null) {
                    $.messager.alert("注意", "请选择一条数据!", "info");
                    return;
                }
                $('#editForm').form('reset');
                var json = {};
                for (var k in row) {
                    $(json).attr("shangPin." + k, row[k]);
                }
                $(json).attr("op", "edit");

                $('#editForm').form('load', json);
                $('#editDialog').dialog('open').dialog('setTitle', '编辑');
            }

            //编辑
            $("#edit").click(function () {
                edit();
            });
            //查看
            function view(field) {
                var row = getDataGridSelectedRow();
                if (!row || row == undefined || row == null) {
                    $.messager.alert("注意", "请选择一条数据!", "info");
                    return;
                }
                for (var k in row) {
                    var str = row[k] ? row[k] : "";
                if (k == "")
                {

                }
                    $("#view_" + k).text(str);
                }
                $('#viewDialog').dialog('open').dialog('setTitle', '查看');
            }

            //查看
            $("#view").click(function () {
                view();

            });
            //保存
            $("#addSaveButton").click(function () {
                action($("#addForm"), "add");
            });
            //保存
            $("#editSaveButton").click(function () {
                action($("#editForm"), "edit");
            });
            //查询
            $("#searchButton").click(function () {
                $("#dg").datagrid("load", $("#searchForm").serializeJson());
            });
            //刷新
            function refresh() {
                $("#dg").datagrid("load", $("#searchForm").serializeJson());
            }
            //刷新
            $("#refresh").click(function () {
                refresh();
            });

            //重置
            $("#resetButton").click(function () {
                $('#searchForm').form('reset');
                refresh();
            });
            del = function (id) {
                //获取选中的ID串
                var ids;
                if (id) {
                    ids = id;
                } else {
                    ids = getDataGridSelectedDatas('id');
                }
                if (ids.length <= 0) {
                    $.messager.alert("注意", "请选择至少一条数据", "info");
                    return;
                }
                $.messager.confirm('注意', '确定删除吗?', function (r) {
                    if (r) {
                        $.messager.progress({
                            title: '请稍后',
                            msg: '操作进行中...'
                        });
                        $.ajax({
                            url: "/project/shangPin",
                            data: {'ids': ids, 'op': 'delete'},
                            type: "Post",
                            dataType: "json",
                            success: function (data) {
                                $.messager.progress('close');
                                showMsg("删除成功");
                                refresh();
                                if (data.errcode != 0) {
                                    $.messager.alert("错误", data.errmsg, "error");
                                }
                            },
                            error: function (data) {
                                $.messager.progress('close');
                                $.messager.alert('错误', data, "error");
                            }
                        });
                    }
                });
            }
            //删除
            $("#delete").click(function () {
                del();
            });
            init = false;
            setTimeout(function () {
                $.parser.parse();
            }, 1000);
        });
    </script>
</head>
<body>
<div id='Loading'
     style="position:absolute;z-index:1000;top:0px;left:0px;width:100%;height:100%;background:#DDDDDB;text-align:center;padding-top: 20%;">
    <h1><img src="/js/easyui/themes/gray/images/loading.gif"><font color="#15428B">加载中···</font></h1></div>
<table width="100%" id="dg" toolbar="#dg_tb"></table>
<div id="dg_tb" style="padding:3px; height: auto">
    <div style="height:30px;" class="datagrid-toolbar">
	<span style="float:left;">

	<a id="add" href="javascript:" class="easyui-linkbutton" plain="true" icon="add">添加</a>
	<a id="edit" href="javascript:" class="easyui-linkbutton" plain="true" icon="icon-edit">编辑</a>
	<a id="delete" href="javascript:" class="easyui-linkbutton" plain="true" icon="delete">删除</a>
	<a id="view" href="javascript:" class="easyui-linkbutton" plain="true" icon="icon-search">查看</a>
        <a id="refresh" href="javascript:" class="easyui-linkbutton" plain="true" icon="arrowrefresh">刷新</a>

	</span>
    </div>
    <div name="searchPanel">

        <form id="searchForm" action="/systemManager/userManager" method="post">
            <input type="hidden" name="op" value="view"/>
            <table style="font-size: 12px;text-align: right">
                <tr>
                <td>商品名称:</td>
            <td class="tdRightPadding">
                    <input    name="shangPin.name"
                                           data-options="required:false,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
                    </td>
                <td>品牌:</td>
            <td class="tdRightPadding">
                    <input    name="shangPin.pingPai"
                                           data-options="required:false,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
                    </td>
                    <td></td>
                    <td><a href="javascript:" id="searchButton" class="easyui-linkbutton" icon="find">查询</a><a
                            href="javascript:" id="resetButton" class="easyui-linkbutton" icon="erase">重置</a></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<div id="addDialog" class="easyui-dialog" style="width: 800px; height: auto; padding: 10px 20px"
     data-options="closed:true,buttons:'#addDialog-buttons',modal:true,iconCls:'icon-add'">
    <form id="addForm" action="/systemManager/userManager" method="post">
        <input type="hidden" name="op" value="add"/>
        <table style="font-size: 12px;text-align: right">
            <tr>
            <td>商品名称:</td>
            <td class="tdRightPadding">
                    <input id="add_name"  
                           name="shangPin.name"
                           data-options="required:true,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
            </td>
            <td>品牌:</td>
            <td class="tdRightPadding">
                    <input id="add_pingPai"  
                           name="shangPin.pingPai"
                           data-options="required:true,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
            </td>
            <td>类别:</td>
            <td class="tdRightPadding">
                    <input id="add_leibie"  style='width:110px'
                           name="shangPin.leibie"
                           data-options="required:false,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
            </td>
            </tr>

        </table>
    </form>
    <div id="addDialog-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" id="addSaveButton"
           data-options="iconCls:'icon-save',plain:true">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true"
           onclick="javascript:$('#addDialog').dialog('close')">取消</a>
    </div>
</div>
<div id="editDialog" class="easyui-dialog" style="width: 800px; height: auto; padding: 10px 20px"
     data-options="closed:true,buttons:'#editDialog-buttons',modal:true,iconCls:'icon-edit'">
    <form id="editForm" action="/systemManager/userManager" method="post">
        <input type="hidden" name="op" value="edit"/>
        <input type="hidden" name="shangPin.id" value="0"/>
        <table style="font-size: 12px;text-align: right">
            <tr>
            <td>商品名称:</td>
            <td class="tdRightPadding">

                    <input id="edit_name"  
                           name="shangPin.name"
                           data-options="required:true,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
            </td>
            <td>品牌:</td>
            <td class="tdRightPadding">

                    <input id="edit_pingPai"  
                           name="shangPin.pingPai"
                           data-options="required:true,validType:{length:[0,50]}" class="f1 easyui-textbox"/>
            </td>
            </tr>
        </table>
    </form>
    <div id="editDialog-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" id="editSaveButton"
           data-options="iconCls:'icon-save',plain:true">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true"
           onclick="javascript:$('#editDialog').dialog('close')">取消</a>
    </div>
</div>
<div id="viewDialog" class="easyui-dialog" style="width: 800px;  padding: 10px 20px"
     data-options="closed:true,buttons:'#viewDialog-buttons',modal:true,iconCls:'icon-search'">
    <table style="font-size: 12px;text-align: right" id="subable">
        <tr>
        <td>商品名称:</td>
        <td class="tdRightPadding" id="view_name"></td>
        <td>品牌:</td>
        <td class="tdRightPadding" id="view_pingPai"></td>
        </tr>
    </table>
    <div id="viewDialog-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true"
           onclick="javascript:$('#viewDialog').dialog('close')">取消</a>
    </div>
</div>
</body>
</html>